package com.ququ.syb.withdraworder.controller;

import com.ququ.common.result.Result;
import com.ququ.syb.common.pojo.WithdrawOrder;
import com.ququ.syb.withdraworder.service.WithdrawOrderService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WithdrawOrderController {
    @Autowired
    private WithdrawOrderService withdrawOrderService;

    @RequestMapping("/query")
    public Result<WithdrawOrder> queryWithdrawOrder(@RequestParam(required = false) String tradenum,
                                                    @RequestParam(required = false) String outordernum){
        WithdrawOrder withdrawOrder = null;
        if (StringUtils.isNotBlank(tradenum))
            withdrawOrder = withdrawOrderService.getWithdrawOrder(tradenum);
        else if (StringUtils.isNotBlank(outordernum))
            withdrawOrder = withdrawOrderService.getWithdrawOrderByOutOrderNum(outordernum);
        if (withdrawOrder == null)
            return new Result<>(-1,"无此提现订单");
        else
            return new Result<>(withdrawOrder);
    }

    @RequestMapping("/list")
    public Result<List<WithdrawOrder>> listWithdrawOrderByPayTradenum(@RequestParam String paytradenum){
        List<WithdrawOrder> withdrawOrderList = withdrawOrderService.listWithdrawOrderByPayTradenum(paytradenum);
        if (withdrawOrderList == null || withdrawOrderList.size() == 0)
            return new Result<>(-1,"无此提现订单");
        else
            return new Result<>(withdrawOrderList);
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public Result<WithdrawOrder> saveWithdrawOrder(@RequestBody WithdrawOrder withdrawOrder){
        withdrawOrder = withdrawOrderService.save(withdrawOrder);
        if (withdrawOrder == null)
            return new Result<>(-1,"无此提现订单");
        else
            return new Result<>(withdrawOrder);
    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result<WithdrawOrder> updateWithdrawOrder(@RequestBody WithdrawOrder withdrawOrder){
        withdrawOrder = withdrawOrderService.update(withdrawOrder);
        if (withdrawOrder == null)
            return new Result<>(-1,"无此提现订单");
        else
            return new Result<>(withdrawOrder);
    }

}
